package cn.hfatec.shms.web.wk.wkGsgl.service;

import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.wk.wkGsgl.model.WkGsgl;
import cn.hfatec.shms.web.wk.wkGsgl.dao.WkGsglDao;
import cn.hfatec.shms.web.wk.wkGsgl.model.WkGsglParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("WkGsglService")
public class WkGsglService {

    public static final String BEAN_ID = "WkGsglService";

    //注入Dao层
    @Resource(name = "WkGsglDao")
    private WkGsglDao wkGsglDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param wkGsglParams
     * @param page
     *
     */
    @Transactional
    public Table queryWkGsglTable(WkGsglParams wkGsglParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", wkGsglParams);
        return baseDao.queryTableByPage("queryWkGsgl", params, page);
    }

    /**
     *
     * 插入数据
     * @param wkGsgl
     *
     */
    @Transactional
    public void saveWkGsgl(WkGsgl wkGsgl) {
        if(wkGsgl.getId() != null) {
            WkGsgl result = getWkGsgl(wkGsgl.getId());
            if(result != null) {
                wkGsglDao.update(wkGsgl);
            } else {
                wkGsglDao.insert(wkGsgl);
            }
        } else {
            wkGsglDao.insert(wkGsgl);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteWkGsgl(Integer id) {

        wkGsglDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param wkGsglList
     *
     */
    @Transactional
    public void deleteWkGsglBatch(List<String> wkGsglList) {
        for(String id : wkGsglList) {
            deleteWkGsgl(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public WkGsgl getWkGsgl(Integer id) {

        return wkGsglDao.getWkGsglById(id);
    }
}